package com.example.demo;

import cn.hutool.http.HttpUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Controller
public class TestController {

    @Mapping("/")
    public Object home() {
        Map<String, Object> data = new LinkedHashMap<>();
        data.put("time1", LocalDateTime.now());
        data.put("time2", LocalDate.now());
        data.put("time3", new Date());
        data.put("time4", null);

        return data;
    }

    @Mapping("/hello")
    public Object hello(String name) {
        return name;
    }

    @Mapping("/test")
    public void test() throws JsonProcessingException {
        String result = HttpUtil.get("http://localhost:8080/");
        JsonNode jsonNode = new XmlMapper().readTree(result);
        System.out.println(jsonNode.get("time1").asText().length());
        System.out.println(jsonNode.get("time2").asText().length());
        System.out.println(jsonNode.get("time3").asLong() > 1000000000);
    }

}
